package com.galeno.utils;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

/**
 * 此类已经过时
 * @author galeno
 * @Title: Hbase工具类
 * @Description:获取hbase客户端对象 调用方法 核心对象:table 和表有关的操作 DML admin 管理对象 DDL Tools split flush....
 * @date 2021/11/1020:28
 */
@Deprecated
public class HbaseUtils作废 {
    static Connection con = null;
    static Configuration conf = null;
    static Admin admin = null;

    static {
        conf = HBaseConfiguration.create();
        try {
            //创建Hbase连接
            con = ConnectionFactory.createConnection(conf);
            admin = con.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Deprecated
    public static void getDataWay(String tableName, HashMap<String,String> map) throws IOException {
        Table table = con.getTable(TableName.valueOf(tableName));
        Scan scan = new Scan();
        ResultScanner scanner = table.getScanner(scan);
        // Result行
        Iterator<Result> resultIterator = scanner.iterator();

        while (resultIterator.hasNext()) {
            //获取行数据
            Result rowData = resultIterator.next();
            while (rowData.advance()) {
                //获取单元格,遍历单元格
                Cell cell = rowData.current();
                //解析单元格
                byte[] cloneRow = CellUtil.cloneRow(cell);
                byte[] cloneFamily = CellUtil.cloneFamily(cell);
                byte[] cloneQualifier = CellUtil.cloneQualifier(cell);
                byte[] cloneValue = CellUtil.cloneValue(cell);
                map.put(new String(cloneQualifier),new String(cloneValue));
            }



        }


    }

    @Deprecated
    public static void getDataWay2(String tableName) throws IOException {
        Table table = con.getTable(TableName.valueOf(tableName));
        Scan scan = new Scan();
        ResultScanner scanner = table.getScanner(scan);
        // Result行
        Iterator<Result> resultIterator = scanner.iterator();

        while (resultIterator.hasNext()) {
            //获取行数据
            Result rowData = resultIterator.next();
            while (rowData.advance()) {
                //获取单元格,遍历单元格
                Cell cell = rowData.current();
                //解析单元格
                byte[] cloneRow = CellUtil.cloneRow(cell);
                byte[] cloneFamily = CellUtil.cloneFamily(cell);
                byte[] cloneQualifier = CellUtil.cloneQualifier(cell);
                byte[] cloneValue = CellUtil.cloneValue(cell);
                System.out.println(new String(cloneRow) + ":" +
                        ":" + new String(cloneFamily) +
                        ":" + new String(cloneQualifier) +
                        "" + new String(cloneValue));
            }



        }


    }


}
